package com.dq.usercenter.controller;

import com.dq.commonutils.vo.Result;
import com.dq.usercenter.service.UcenterMemberService;
import com.dq.usercenter.vo.UserMemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * UcenterMember-API
 *
 * @author Dq
 * @since 2022-08-07 17:18:43
 */
@RestController
@RequestMapping("educenter/member")
// @CrossOrigin
public class UcenterMemberController {

    @Autowired
    private UcenterMemberService userMapper;

    /**
     * 登录
     *
     * @param userMemberVo
     * @return
     */
    @PostMapping("login")
    public Result loginUser(@RequestBody UserMemberVo userMemberVo) {
        String token = userMapper.loginUser(userMemberVo);
        HashMap<String, String> resultMap = new HashMap<>();
        resultMap.put("token", token);
        return Result.success(resultMap);
    }

    /**
     * 注册用户
     *
     * @param userMemberVo
     * @return
     */
    @PostMapping("register")
    public Result register(@RequestBody UserMemberVo userMemberVo) {
        String token = userMapper.register(userMemberVo);
        HashMap<String, String> resultMap = new HashMap<>();
        resultMap.put("token", token);
        return Result.success(resultMap);
    }

    /**
     * 退出功能
     *
     * @param token
     * @return
     */
    @GetMapping("logout")
    public Result logout(@RequestHeader("Authorization") String token) {
        userMapper.logout(token);
        return Result.success(null);
    }



}